<?php $path = Router::url(array('controller' => '/', 'action' =>''), true);?>
<script>
$(document).ready(function(){
    $("ul.contact_list li.title a.first").click(function(){
       if($(this).parent().hasClass('current')){
            $(this).next('ul').slideUp('normal');
            $(this).parent().removeClass('current');
       }else{
            $("ul.contact_list li.title a.first").each(function(){
                $(this).parent().removeClass('current').find('ul').slideUp('normal');
            });
            $(this).next('ul').slideDown('normal');
            $(this).parent().addClass('current');
       }
    });
    $('ul.contact_list li ul li a').click(function(){});
    
    $('.insertUser').dblclick(function(){
        
        if($(this).attr('com_id')==undefined){
           if($("[value="+$(this).attr('user_id')+"][name='users[]']:hidden").length<=0){
               $('#receiver1').append("<span style='float:left;margin-left:5px;' class='deleteUser' user_id="+$(this).attr('user_id')+">"+$(this).attr('title')+" ; </span>");
               $('#receiver1').append("<input type='hidden' name='users[]' value="+$(this).attr('user_id')+" >");
           }
           
        }else{
            if($("[value="+$(this).attr('com_id')+"][name='coms[]']:hidden").length<=0){
                $('#receiver1').append("<span style='float:left;margin-left:5px;' class='deleteUser' com_id="+$(this).attr('com_id')+">"+$(this).attr('title')+" ; </span>");
                $('#receiver1').append("<input type='hidden' name='coms[]' value="+$(this).attr('com_id')+" >");
            }
        }
       
        $('.deleteUser').click(function(){
            if($(this).attr('com_id')==undefined){
                $("[value="+$(this).attr('user_id')+"][name='users[]']:hidden").remove();
            }else{
                $("[value="+$(this).attr('com_id')+"][name='coms[]']:hidden").remove();
            }
            
            $(this).remove();
        });
    });
    (function(){
        for(var i=1;i<=12;i++){
            $("#month_opt").append("<option value='"+i+"'>"+i+"</option>");
        
        }
    
    })()
    
    $("#fixed_time").click(function(){
    
        if($(this).attr("checked")=="checked"){
           $("#timer_id").attr("src","<?php echo $path;?>img/time_run.png");
           $("#month_opt").removeAttr("disabled"); 
        }else{
            $("#timer_id").attr("src","<?php echo $path;?>img/timer.png");
            $("#month_opt").attr("disabled","disabled"); 
        }
    
    });
    ajax_upload_file('ajax_upload_file','ajax_file_list');
    //$("#month_opt").uniform({background:"red"});
    //$(".ajax_upload_file").uniform();
    //$("#fixed_time").uniform();
    //$("#post").uniform();
});
</script>
<style>

#uniform-post{
    float:right;
    margin-right:40px;
}

.ajax_upload_fileForm{
width: 40%;
float:left;
}
</style>


<div class="right_side_scollbar_msg" style="height:100%">

<div style="float:left;width:72%;margin-left:25px;margin-top:10px;">
 <?php echo $form->create('Msg', array('action' => 'add','type'=> 'post','id' => 'addform','name' => 'form','enctype'=>'multipart/form-data','onsubmit' => "return addcheckinfo()") ); 
        ?>
  <input name="msg_type" type="hidden" value="<?php echo $msg_type;?>" />
<!--  <div style='font-size:10pt;' >收件人：<div style="position:relative;top: -18px;left: 60px;width:83%;overflow: auto;" id="receiver1"></div></div>-->
<!--  <div class="clear" ></div>-->
  <div style='font-size:10pt;margin:10px 0;'>主题：&nbsp;&nbsp;&nbsp;<input style='width:82%' id="subject" name="subject"></div>
  <div style='font-size:10pt;' >收件人：<div style="position:relative;top: -18px;left: 60px;width:82%;overflow: auto;" id="receiver1"></div></div>
<!--  <div class="clear" ></div>-->
  <div style='font-size:11pt;'>	
    <textarea style='width:90%;height:200px;padding:5px;' id="content" name="content"></textarea>
    <div style='width:100%;float:left;'>
    <div style='font-size:10pt;margin:0 0 10px 0;' class="ajax_file_list">附件：&nbsp;&nbsp;</div>
    <input type="file" style="width: 100%;"  class="ajax_upload_file" name='upload[]'>
    <font color='#d70000' style="float:left;line-height: 26px;display:none"  size='1'>*最多上传5个附件</font>
    <?php if($msg_type=='sys'):?>
    <div style="height:30px;line-height:30px;width:400px;margin-top:5px;float:left;font-size:13px;">   
    <?php echo $html->image('timer.png',array('width'=>'20','id'=>"timer_id",'style'=>'margin: 6px 4px;float: left;'));?>定时发送:
   <input type="checkbox" id="fixed_time"  name="fixed_time" value="1">每隔<select disabled  name="month_opt"  id="month_opt"></select>个月发送一次
    </div>
    <?php endif;?>
    <input id="post" type="submit" value="发&nbsp;&nbsp;送" style='float:right;margin-right:50px;background: #4298e5;width: 100px;height: 30px;border: 0;font-size: 12pt;color: #fff;cursor: pointer;'></div>
  </div>
  </form>
</div>
  
<div style='float:left;width:24%;margin-top:10px;background:#fff;border-top:1px solid #ccc;'>
  <h3 style='text-indent:15px;font-size:12pt;background:#eee;height:30px;line-height:30px;'>双击选择收件人</h3>
  <ul class='contact_list'>
   <li class='title'><a href='javascript:;' class='first'>园内企业</a>
    <ul style='float:left;width:85%;'>
        <?php foreach($companies as $company):?>
        <li><a href='javascript:;' class="insertUser" com_id='<?php echo $company['companies']['id'];?>' title="<?php echo $company['companies']['company_name'];?>"><?php echo $str->sub_len($company['companies']['company_name'],8);?></a></li>
        <?php endforeach;?>
        </ul>
    </li>
    <?php $n = 1;?>
    <?php foreach($groups as $group):?>
    <?php if($n == 1){$id = $group['Group']['id'];}?>
    <?php if($group['Group']['id'] != $id || $n == 1): ?>
   <li class='title'><a href='javascript:;' class='first'><?php echo $group['Group']['group_name'];?></a>
    <ul style='float:left;width:85%;'>
        <?php foreach($group['User'] as $user):?>
        <li><a href='javascript:;' class="insertUser" user_id="<?php echo $user['id']?>" title="<?php echo $user['name']?>"><?php echo $text->excerpt($user['name'],'',10);?></a></li>
        <?php endforeach;?>
        </ul>
    </li>
    <?php $n++;?>
    <?php endif;?>
    <?php $id = $group['Group']['id']; ?>
    <?php endforeach;?>
  </ul>
</div>

<div class="clear" style='height:50px;float:left;width:100%;'></div>
</div>
<script>

(function(){
  var addcheckinfo = function(){
  
        if(($("[name='users[]']:hidden").length<=0) && ($("[name='coms[]']:hidden").length<=0)){
              alert('请选择收件人');
                return false;
        }
  
          if($("#subject").val().trim() == ''){
            alert('请填写主题');
            return false;
          }
          if($("#content").val().trim() == ''){
           alert('请填写内容');
            return false;
          }
          
         
        
    }
    window.addcheckinfo = addcheckinfo;
})()
</script>